{"ast":null,"code":"var _jsxFileName = \"/data/messenger.client/src/components/DialogItem/index.tsx\",\n  _s = $RefreshSig$();\nimport React from 'react';\nimport { getLastMessage, getUserNameLastMessage } from \"../../utils/Chat\";\nimport { getHelloMessage } from \"../../utils/Message\";\nimport { getOtherUserForNotMultiChat } from \"../../utils/Membership\";\nimport { getUserName } from \"../../utils/User\";\nimport { MessageDate, MessageStatus, Avatar, Name } from \"../\";\nimport { Context } from \"../../index\";\nimport classNames from \"classnames\";\nimport './Dialog.scss';\nimport { jsxDEV as _jsxDEV } from \"react/jsx-dev-runtime\";\nconst DialogItem = _ref => {\n  _s();\n  var _lastMessage$bodyMess;\n  let {\n    chat\n  } = _ref;\n  const {\n    store\n  } = React.useContext(Context);\n  const [otherUser, setOtherUser] = React.useState();\n  const [lastMessage, setLastMessage] = React.useState(chat.lastMessage || getHelloMessage(store));\n  React.useEffect(() => {\n    if (!chat.multiChat && chat.membership && chat.membership.items.length > 0) {\n      setOtherUser(getOtherUserForNotMultiChat(store, chat.membership));\n    }\n    if (chat.messages && chat.messages.items.length > 0) {\n      setLastMessage(getLastMessage(chat.messages));\n    } else {\n      setLastMessage(getHelloMessage(store));\n    }\n  }, [chat, store.chats, store]);\n  return /*#__PURE__*/_jsxDEV(\"div\", {\n    className: classNames('dialogs__item', {\n      'dialogs__item--online': !chat.multiChat\n    }),\n    onSelect: () => store.setCurrentDialog(chat),\n    children: [/*#__PURE__*/_jsxDEV(\"div\", {\n      className: \"dialogs__item--avatar\",\n      children: [chat.multiChat && /*#__PURE__*/_jsxDEV(Avatar, {\n        contentList: chat.content,\n        alt: chat.name,\n        stringForFirstCharacter: chat.name,\n        stringForGenerateColor: chat.name\n      }, void 0, false, {\n        fileName: _jsxFileName,\n        lineNumber: 39,\n        columnNumber: 21\n      }, this), !chat.multiChat && otherUser && /*#__PURE__*/_jsxDEV(Avatar, {\n        contentList: otherUser.content,\n        alt: getUserName(otherUser),\n        stringForFirstCharacter: getUserName(otherUser),\n        stringForGenerateColor: otherUser.id\n      }, void 0, false, {\n        fileName: _jsxFileName,\n        lineNumber: 47,\n        columnNumber: 21\n      }, this)]\n    }, void 0, true, {\n      fileName: _jsxFileName,\n      lineNumber: 37,\n      columnNumber: 13\n    }, this), /*#__PURE__*/_jsxDEV(\"div\", {\n      className: \"dialogs__item-info\",\n      children: [/*#__PURE__*/_jsxDEV(\"div\", {\n        className: \"dialogs__item-info-top\",\n        children: [/*#__PURE__*/_jsxDEV(Name, {\n          user: otherUser,\n          chatName: chat.name,\n          multiChat: chat.multiChat\n        }, void 0, false, {\n          fileName: _jsxFileName,\n          lineNumber: 57,\n          columnNumber: 20\n        }, this), chat.messages && chat.messages.items.length > 0 && /*#__PURE__*/_jsxDEV(MessageDate, {\n          message: lastMessage,\n          shortDate: true\n        }, void 0, false, {\n          fileName: _jsxFileName,\n          lineNumber: 59,\n          columnNumber: 77\n        }, this)]\n      }, void 0, true, {\n        fileName: _jsxFileName,\n        lineNumber: 56,\n        columnNumber: 17\n      }, this), chat.multiChat && lastMessage && /*#__PURE__*/_jsxDEV(\"div\", {\n        className: \"dialogs__item-info-medium\",\n        children: /*#__PURE__*/_jsxDEV(\"p\", {\n          children: getUserNameLastMessage(lastMessage.user, store)\n        }, void 0, false, {\n          fileName: _jsxFileName,\n          lineNumber: 64,\n          columnNumber: 25\n        }, this)\n      }, void 0, false, {\n        fileName: _jsxFileName,\n        lineNumber: 63,\n        columnNumber: 21\n      }, this), /*#__PURE__*/_jsxDEV(\"div\", {\n        className: \"dialogs__item-info-bottom\",\n        children: [/*#__PURE__*/_jsxDEV(\"p\", {\n          children: lastMessage === null || lastMessage === void 0 ? void 0 : (_lastMessage$bodyMess = lastMessage.bodyMessage) === null || _lastMessage$bodyMess === void 0 ? void 0 : _lastMessage$bodyMess.message\n        }, void 0, false, {\n          fileName: _jsxFileName,\n          lineNumber: 68,\n          columnNumber: 21\n        }, this), lastMessage && /*#__PURE__*/_jsxDEV(MessageStatus, {\n          message: lastMessage,\n          store: store,\n          dialog: true\n        }, void 0, false, {\n          fileName: _jsxFileName,\n          lineNumber: 69,\n          columnNumber: 37\n        }, this), chat.unreadMessageCounter !== 0 && /*#__PURE__*/_jsxDEV(\"div\", {\n          className: \"dialogs__item-info-bottom-count\",\n          children: chat.unreadMessageCounter && chat.unreadMessageCounter > 9 ? '+9' : chat.unreadMessageCounter\n        }, void 0, false, {\n          fileName: _jsxFileName,\n          lineNumber: 71,\n          columnNumber: 25\n        }, this)]\n      }, void 0, true, {\n        fileName: _jsxFileName,\n        lineNumber: 67,\n        columnNumber: 17\n      }, this)]\n    }, void 0, true, {\n      fileName: _jsxFileName,\n      lineNumber: 55,\n      columnNumber: 13\n    }, this)]\n  }, void 0, true, {\n    fileName: _jsxFileName,\n    lineNumber: 33,\n    columnNumber: 9\n  }, this);\n};\n_s(DialogItem, \"rvcSz239dQZ2mkyZD+L3QAG0ALA=\");\n_c = DialogItem;\nexport default DialogItem;\nvar _c;\n$RefreshReg$(_c, \"DialogItem\");","map":{"version":3,"names":["React","getLastMessage","getUserNameLastMessage","getHelloMessage","getOtherUserForNotMultiChat","getUserName","MessageDate","MessageStatus","Avatar","Name","Context","classNames","DialogItem","chat","store","useContext","otherUser","setOtherUser","useState","lastMessage","setLastMessage","useEffect","multiChat","membership","items","length","messages","chats","setCurrentDialog","content","name","id","user","bodyMessage","message","unreadMessageCounter"],"sources":["/data/messenger.client/src/components/DialogItem/index.tsx"],"sourcesContent":["import React from 'react';\nimport {DialogsItemProps} from \"../../models/props/DialogsItemProps\";\nimport {getLastMessage, getUserNameLastMessage} from \"../../utils/Chat\";\nimport {getHelloMessage} from \"../../utils/Message\";\nimport {getOtherUserForNotMultiChat} from \"../../utils/Membership\";\nimport {getUserName} from \"../../utils/User\";\nimport {MessageDate, MessageStatus, Avatar, Name} from \"../\";\nimport {MessagesListItem} from \"../../models/response/MessagesListItem\";\nimport {UserListItem} from \"../../models/response/UserListItem\";\nimport {Context} from \"../../index\";\nimport classNames from \"classnames\";\nimport './Dialog.scss';\n\nconst DialogItem: React.FC<DialogsItemProps> = ({chat}) => {\n    const {store} = React.useContext(Context);\n    const [otherUser, setOtherUser] = React.useState<UserListItem>();\n    const [lastMessage, setLastMessage] = React.useState<MessagesListItem>(\n        (chat.lastMessage || getHelloMessage(store))\n    );\n\n    React.useEffect(() => {\n            if (!chat.multiChat && chat.membership && chat.membership.items.length > 0) {\n                setOtherUser(getOtherUserForNotMultiChat(store, chat.membership));\n            }\n            if (chat.messages && chat.messages.items.length > 0) {\n                setLastMessage(getLastMessage(chat.messages));\n            } else {\n                setLastMessage(getHelloMessage(store));\n            }\n    }, [chat, store.chats, store]);\n\n    return (\n        <div\n            className={classNames('dialogs__item', {'dialogs__item--online' : !chat.multiChat})}\n            onSelect={() => store.setCurrentDialog(chat)}\n        >\n            <div className=\"dialogs__item--avatar\">\n                {chat.multiChat &&\n                    <Avatar\n                        contentList={chat.content}\n                        alt={chat.name}\n                        stringForFirstCharacter={chat.name}\n                        stringForGenerateColor={chat.name}\n                    />\n                }\n                {!chat.multiChat && otherUser &&\n                    <Avatar\n                        contentList={otherUser.content}\n                        alt={getUserName(otherUser)}\n                        stringForFirstCharacter={getUserName(otherUser)}\n                        stringForGenerateColor={otherUser.id}\n                    />\n                }\n            </div>\n            <div className=\"dialogs__item-info\">\n                <div className=\"dialogs__item-info-top\">\n                   <Name user={otherUser} chatName={chat.name} multiChat={chat.multiChat} />\n                   {\n                       (chat.messages && chat.messages.items.length > 0) && <MessageDate message={lastMessage} shortDate={true} />\n                    }\n                </div>\n                {chat.multiChat && lastMessage &&\n                    <div className='dialogs__item-info-medium'>\n                        <p>{getUserNameLastMessage(lastMessage.user, store)}</p>\n                    </div>\n                }\n                <div className=\"dialogs__item-info-bottom\">\n                    <p>{lastMessage?.bodyMessage?.message}</p>\n                    {lastMessage && <MessageStatus message={lastMessage} store={store} dialog={true} />}\n                    {chat.unreadMessageCounter !== 0 &&\n                        <div className=\"dialogs__item-info-bottom-count\">\n                            {(chat.unreadMessageCounter && chat.unreadMessageCounter > 9)? '+9': chat.unreadMessageCounter}\n                        </div>\n                    }\n                </div>\n            </div>\n        </div>\n    );\n}\n\nexport default DialogItem;"],"mappings":";;AAAA,OAAOA,KAAK,MAAM,OAAO;AAEzB,SAAQC,cAAc,EAAEC,sBAAsB,QAAO,kBAAkB;AACvE,SAAQC,eAAe,QAAO,qBAAqB;AACnD,SAAQC,2BAA2B,QAAO,wBAAwB;AAClE,SAAQC,WAAW,QAAO,kBAAkB;AAC5C,SAAQC,WAAW,EAAEC,aAAa,EAAEC,MAAM,EAAEC,IAAI,QAAO,KAAK;AAG5D,SAAQC,OAAO,QAAO,aAAa;AACnC,OAAOC,UAAU,MAAM,YAAY;AACnC,OAAO,eAAe;AAAC;AAEvB,MAAMC,UAAsC,GAAG,QAAY;EAAA;EAAA;EAAA,IAAX;IAACC;EAAI,CAAC;EAClD,MAAM;IAACC;EAAK,CAAC,GAAGd,KAAK,CAACe,UAAU,CAACL,OAAO,CAAC;EACzC,MAAM,CAACM,SAAS,EAAEC,YAAY,CAAC,GAAGjB,KAAK,CAACkB,QAAQ,EAAgB;EAChE,MAAM,CAACC,WAAW,EAAEC,cAAc,CAAC,GAAGpB,KAAK,CAACkB,QAAQ,CAC/CL,IAAI,CAACM,WAAW,IAAIhB,eAAe,CAACW,KAAK,CAAC,CAC9C;EAEDd,KAAK,CAACqB,SAAS,CAAC,MAAM;IACd,IAAI,CAACR,IAAI,CAACS,SAAS,IAAIT,IAAI,CAACU,UAAU,IAAIV,IAAI,CAACU,UAAU,CAACC,KAAK,CAACC,MAAM,GAAG,CAAC,EAAE;MACxER,YAAY,CAACb,2BAA2B,CAACU,KAAK,EAAED,IAAI,CAACU,UAAU,CAAC,CAAC;IACrE;IACA,IAAIV,IAAI,CAACa,QAAQ,IAAIb,IAAI,CAACa,QAAQ,CAACF,KAAK,CAACC,MAAM,GAAG,CAAC,EAAE;MACjDL,cAAc,CAACnB,cAAc,CAACY,IAAI,CAACa,QAAQ,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